package com.slicktechnologies.client.views.settings.company;
import com.google.gwt.event.dom.client.ClickEvent;

import java.util.*;

import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;
import com.simplesoftwares.client.library.appstructure.*;
import com.simplesoftwares.client.library.appstructure.search.*;
import com.simplesoftwares.client.library.appstructure.formscreen.*;
import com.slicktechnologies.shared.*;
import com.slicktechnologies.shared.common.*;
import com.slicktechnologies.shared.common.businessprocesslayer.*;
import com.slicktechnologies.shared.common.businessunitlayer.*;
import com.slicktechnologies.shared.common.helperlayer.*;
import com.slicktechnologies.shared.common.personlayer.*;
import com.slicktechnologies.shared.common.productlayer.*;
import com.simplesoftwares.client.library.appskeleton.AppMemory;
import com.simplesoftwares.client.library.libservice.GenricService;
import com.simplesoftwares.client.library.libservice.GenricServiceAsync;
import com.google.gwt.core.shared.GWT;
import com.slicktechnologies.client.utility.GeneratedVariableRefrence;
import com.simplesoftwares.rebind.annatonations.EntityNameAnnotation;
import com.slicktechnologies.shared.common.paymentlayer.*;
import com.google.gwt.event.dom.client.*;
/**
 * FormScreen presenter template.
 */
public class CompanyPresenter extends FormScreenPresenter<Company>{

	//Token to set the concrete FormScreen class name
	CompanyForm form;
	GenricServiceAsync async =GWT.create(GenricService.class);
	
	public CompanyPresenter  (FormScreen<Company> view, Company model) {
		super(view, model);
		form=(CompanyForm) view;
		form.showWaitSymbol();
		Timer timer=new Timer() {
				
				@Override
				public void run() {
					retriveCompany();
			    
			             
				}
			};
			 timer.schedule(5000); 
		
		}
	

	

	/**
	 * Method token to make new model
	 */
	@Override
	protected void makeNewModel() {
		model=new Company();
	}
	
	
	
	
	public static void initalize()
	{
		CompanyForm  form=new  CompanyForm();
		
		
		//// CompanyPresenterTable gentable=GWT.create( CompanyPresenterTable.class);
		////  gentable.setView(form);
		////  gentable.applySelectionModle();
		//// CompanyPresenterSearch.staticSuperTable=gentable;
		//// CompanyPresenterSearch searchpopup=GWT.create( CompanyPresenterSearch.class);
		////form.setSearchpopupscreen(searchpopup);
		
		
		 CompanyPresenter  presenter=new CompanyPresenter(form,new Company());
		AppMemory.getAppMemory().stickPnel(form);
	}
	
	@EntityNameAnnotation(EntityName = "com.slicktechnologies.shared.common.businessunitlayer.Company")
	 public static  class CompanyPresenterSearch extends SearchPopUpScreen<Company>{

		@Override
		public MyQuerry getQuerry() {
			// TODO Auto-generated method stub
			return null;
		}};
		
		@EntityNameAnnotation(EntityName = "com.slicktechnologies.shared.common.businessunitlayer.Company")
		 public static class CompanyPresenterTable extends SuperTable<Company> implements GeneratedVariableRefrence{

			@Override
			public Object getVarRef(String varName) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public void createTable() {
				// TODO Auto-generated method stub
				
			}

			@Override
			protected void initializekeyprovider() {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void addFieldUpdater() {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void setEnable(boolean state) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void applyStyle() {
				// TODO Auto-generated method stub
				
			}} ;
			
	
	
		  
		  protected void retriveCompany()
			{
			  MyQuerry myQuer= new MyQuerry();
			  myQuer.setQuerryObject(new Company());
			  
			  async.getSearchResult(myQuer,new AsyncCallback<ArrayList<SuperModel>>() {

				@Override
				public void onFailure(Throwable caught) {
					// TODO Auto-generated method stub
					form.hideWaitSymbol();
					
				}

				@Override
				public void onSuccess(ArrayList<SuperModel> result) {
					form.hideWaitSymbol();
					model=(Company) result.get(0);
					form.updateView(model);
					form.setToViewState();
					
					
				}
			});
			}



		@Override
		public void reactToProcessBarEvents(ClickEvent e) {
			// TODO Auto-generated method stub
			
		}



		@Override
		public void reactOnPrint() {
			// TODO Auto-generated method stub
			
		}



		@Override
		public void reactOnEmail() {
			// TODO Auto-generated method stub
			
		}
	
}
